package com.sskj.ffex.v.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.sskj.ffex.MyAppLication;
import com.sskj.ffex.R;
import com.sskj.ffex.common.App;
import com.sskj.ffex.common.Constants;
import com.sskj.ffex.common.rxbus2.RxBus;
import com.sskj.ffex.common.widget.ToolBarLayout;
import com.sskj.ffex.m.bean.UserInfo;
import com.sskj.ffex.p.activity.PersonalPresenter;
import com.sskj.ffex.utils.ClickUtil;
import com.sskj.ffex.utils.SPUtils;
import com.sskj.ffex.v.base.BaseActivity;

import butterknife.BindView;

/**
 * <pre>
 *     author : 李岩
 *     e-mail : 465357793@qq.com
 *     time   : 2018/04/03
 *     desc   : 个人中心
 *     version: 1.0
 * </pre>
 */
public class  PersonalActivity extends BaseActivity<PersonalPresenter> {


    @BindView(R.id.toolBar)
    ToolBarLayout toolBar;
    @BindView(R.id.personal_mobile)
    TextView personalMobile;
    @BindView(R.id.personal_email)
    TextView personalEmail;
    @BindView(R.id.personal_trabcaction_id)
    TextView personalTrabcactionId;
    @BindView(R.id.personal_name)
    TextView personalName;
    @BindView(R.id.personal_ident)
    TextView personalIdent;
    @BindView(R.id.title)
    TextView mTitle;
    @BindView(R.id.textView26)
    TextView textType;  // 手机号还是邮箱
    @BindView(R.id.personal_logout)
    Button logout;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_personal;
    }

    @Override
    public PersonalPresenter getPresenter() {
        return new PersonalPresenter();
    }

    @Override
    protected void onViewBinding() {
//        mTitle.setText(App.INSTANCE.getString(R.string.strPersonalActivity200));

        mPresenter.getUserInfo();
        mTitle.setVisibility(View.GONE);
        toolBar.setTitle(App.INSTANCE.getString(R.string.strPersonalActivity200));
        toolBar.setLeftButtonOnClickLinster(v -> finish());
        ClickUtil.click(logout, () -> {
            RxBus.getDefault().send(Constants.USER_LOGOUT);
            SPUtils.clear(MyAppLication.getMobile());
            startActivity(new Intent(this, LoginActivity.class));
            finish();
        });
//        personalMobile.setText(MyAppLication.getMobile());
//        personalTrabcactionId.setText(MyAppLication.getAccount());
//        personalName.setText(MyAppLication.getName());
//        personalIdent.setText(MyAppLication.getIdCard());
    }

    public void updateUserInfo(UserInfo userInfo) {
        setText(personalEmail,userInfo.getMail());
        setText(personalMobile,userInfo.getMobile());
        setText(personalIdent,userInfo.getIdcard());
        setText(personalName,userInfo.getRealname());
        setText(personalTrabcactionId,userInfo.getAccount());
    }
}
